package com.leyou.auth.config;

import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

import java.security.SecureRandom;

@Data
@Configuration
@ConfigurationProperties("ly.encoder.crypt")
public class PasswordConfig {

    private String secret;
    private int strength;

    @Bean
    public BCryptPasswordEncoder passwordEncoder(){
        /**
         * 参数一：加密强度，不要大于10
         * 参数二：随机盐
         */
        return new BCryptPasswordEncoder(strength, new SecureRandom(secret.getBytes()));
    }
}
